package com.mt.fpb.controller;


import com.github.pagehelper.PageHelper;
import com.mt.fpb.mapper.TMineInfoMapper;
import com.mt.fpb.mapper.TWarningMapper;
import com.mt.fpb.model.TWarning;
import com.mt.fpb.model.dto.BaseQueryParams;
import com.mt.fpb.model.vo.CommonPage;
import com.mt.fpb.model.vo.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 矿山安全-数据中心
 * 2021年6月16日15:52:57
 */
@RestController
@RequestMapping("/DataCenter")
public class SafetyInProductionDataCenter {

    @Resource
    private TMineInfoMapper tMineInfoMapper;
    @Resource
    private TWarningMapper tWarningMapper;

    /**
     * 左上
     * 查询所有矿区
     * t_mine_info  mine_name
     * <p>
     * 2021年6月17日09:39:00
     */
    @GetMapping("/findAllMineArea")
    public CommonResult findAllMineArea(BaseQueryParams queryParams) {
        return CommonResult.success(tMineInfoMapper.selectAll());
    }

    /**
     * 条件查询
     * 时间，矿区
     * <p>
     * 2021年6月17日09:39:07
     */
    @GetMapping("/SafetyInProduction/queryWarningMessage")
    public CommonResult queryWarningMessage(BaseQueryParams queryParams) {
        PageHelper.startPage(queryParams.getPage(), queryParams.getPageSize());
        Example example = new Example(TWarning.class);
        example.createCriteria().
                andBetween("warningTime", queryParams.getBeginTime(), queryParams.getEndTime()).
                andEqualTo(queryParams.getMineId());
        List<TWarning> tWarnings = tWarningMapper.selectByExample(example);
        return CommonResult.success(CommonPage.restPage(tWarnings));
    }

    /**
     * 地磅数据中心
     * <p>
     * 2021年6月17日09:39:17
     */
    @GetMapping("/LoadometerViolation")
    public CommonResult LoadometerViolation(BaseQueryParams queryParams) {

        Map dataMap = new HashMap();
        dataMap.put("mineId", queryParams.getMineId());
        dataMap.put("beginTime", queryParams.getBeginTime());
        dataMap.put("endTime", queryParams.getEndTime());
        PageHelper.startPage(queryParams.getPage(), queryParams.getPageSize());
        List<Map<String, String>> dataCenter =
                tWarningMapper.findDataCenter(dataMap);
        return CommonResult.success(CommonPage.restPage(dataCenter));
    }

    /**
     * 查询详情
     * queryDetails
     * <p>
     * 2021年6月17日09:39:26
     */
    @GetMapping("/queryDetails")
    public CommonResult queryDetails(BaseQueryParams queryParams) {
        PageHelper.startPage(queryParams.getPage(), queryParams.getPageSize());
        List<Map<String, String>> mapList = tWarningMapper.queryDetails(queryParams.getWarningId());
        return CommonResult.success(CommonPage.restPage(mapList));
    }

    /**
     * 任务中心
     * 查询条件
     * 矿区ID 事件类型 状态 开始时间 结束时间
     * <p>
     * 2021年6月17日09:39:31
     */
    @GetMapping("/querytsakCenter")
    public CommonResult tsakCenter(BaseQueryParams queryParams) {
        PageHelper.startPage(queryParams.getPage(), queryParams.getPageSize());
        Map dataMap = new HashMap();
        dataMap.put("mineId", queryParams.getMineId());
        dataMap.put("warningStr", queryParams.getWarningStr());
        dataMap.put("warningType", queryParams.getWarningType());
        dataMap.put("beginTime", queryParams.getBeginTime());
        dataMap.put("endTime", queryParams.getEndTime());

        List<Map<String, String>> mapsList = tWarningMapper.querytsakCenter(dataMap);
        return CommonResult.success(CommonPage.restPage(mapsList));
    }

    /**
     * 任务中心详情查询
     * <p>
     * 2021年6月17日09:39:40
     */
    @GetMapping("/queryConsult")
    public CommonResult queryConsult(BaseQueryParams queryParams) {
        PageHelper.startPage(queryParams.getPage(), queryParams.getPageSize());
        List<Map<String, String>> mapList = tWarningMapper.queryConsult(queryParams.getWarningId());
        return CommonResult.success(CommonPage.restPage(mapList));
    }

}
